// Direct3D_Class project
// Jonathan S. Harbour
// June 2005


#include "CTexture.h"


CTexture::CTexture(LPDIRECT3DDEVICE9 dev)
{
	device = dev;
}

CTexture::~CTexture()
{
	texture->Release();
}

int CTexture::Load(char *filename, D3DCOLOR transcolor)
{
    //the struct for reading bitmap file info
    D3DXIMAGE_INFO info;

    //standard Windows return value
    HRESULT result;
    
    //get width and height from bitmap file
    result = D3DXGetImageInfoFromFile(filename, &info);
    if (result != D3D_OK)
	{
        texture = NULL;
		return 1;
	}

    //create the new texture by loading a bitmap image file
	D3DXCreateTextureFromFileEx( 
        device,              //Direct3D device object
        filename,            //bitmap filename
        info.Width,          //bitmap image width
        info.Height,         //bitmap image height
        1,                   //mip-map levels (1 for no chain)
        D3DPOOL_DEFAULT,     //the type of surface (standard)
        D3DFMT_UNKNOWN,      //surface format (default)
        D3DPOOL_DEFAULT,     //memory class for the texture
        D3DX_DEFAULT,        //image filter
        D3DX_DEFAULT,        //mip filter
        transcolor,          //color key for transparency
        &info,               //bitmap file info (from loaded file)
        NULL,                //color palette
        &texture );          //destination texture

    //make sure the bitmap textre was loaded correctly
    if (result != D3D_OK)
	{
        texture = NULL;
		return 1;
	}

	return 0;
}


